package com.baboba.rummy.web.client;

import com.baboba.rummy.web.client.game.GameView;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.dom.client.Element;
import com.google.gwt.event.dom.client.DragStartEvent;
import com.google.gwt.event.dom.client.DragStartHandler;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Panel;
import com.google.gwt.user.client.ui.RootLayoutPanel;

public class RummyWeb implements EntryPoint {

	@Override
	public void onModuleLoad() {
		
		RootLayoutPanel.get().add(new GameView());
		
		/*// RootLayoutPanel.get().add(createMainPanel());

		final Label dropLabel = new Label("test");
		final Label dragLabel = new Label("test aaa");

		FlowPanel panel = new FlowPanel();

		RootPanel.get().add(panel);

		panel.add(dragLabel);
		panel.add(dropLabel);

		// Configure the draggable element
		dragLabel.getElement().setDraggable(Element.DRAGGABLE_TRUE);
		dragLabel.addDragStartHandler(new DragStartHandler() {
			@Override
			public void onDragStart(DragStartEvent event) {
				event.setData("text", "drag-data");
				event.getDataTransfer().setDragImage(dragLabel.getElement(), 0,
						0);
			}
		});
		dragLabel.addDragEndHandler(new DragEndHandler() {

			@Override
			public void onDragEnd(DragEndEvent event) {
				System.out.println("Drag end");
			}

		});

		// Configure the drop target
		dropLabel.addDragOverHandler(new DragOverHandler() {
			@Override
			public void onDragOver(DragOverEvent event) {
				dropLabel.setText("Dragging Over");
			}
		});
		dropLabel.addDragLeaveHandler(new DragLeaveHandler() {
			@Override
			public void onDragLeave(DragLeaveEvent event) {
				dropLabel.setText("Drop Here");
			}
		});
		dropLabel.addDropHandler(new DropHandler() {
			@Override
			public void onDrop(DropEvent event) {
				System.out.println("Drop finished");
			}
		});*/
	}

	public Panel createMainPanel() {
		FlexTable topPanel = new FlexTable();
		topPanel.setWidth("100%");
		topPanel.setHeight("100%");
		topPanel.setBorderWidth(1);

		for (int i = 0; i < 10; i++)
			for (int l = 0; l < 10; l++) {
				Label widget = new Label("Label " + i + "*" + l);
				widget.getElement().setDraggable(Element.DRAGGABLE_TRUE);
				widget.addDragStartHandler(new DragStartHandler() {

					@Override
					public void onDragStart(DragStartEvent event) {
						System.out.println("Drag start...");
					}

				});
				topPanel.setWidget(i, l, widget);
			}

		return topPanel;
	}
}
